Content starts here SP - Advanced API Samples - Mediator, Web Services, and DSP Controls
This page last changed on Jun 19, 2008.

This page collects the following related topics on a single HTML page:

This arrangement is designed to facilitate printing of the entire topic. Some duplication of references, link headers, and "Related Topics" information may be observed.

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2/3.01 Documentation

Design and code Michael Reiche
Documentation
John Jerney
Version(s) supported
ALDSP 3.2 / 3.01

Getting Started with Advanced API Samples

Prefer all related topics on a single page? Click here.

This advanced topic supplements existing documentation that describes the invocation of ALDSP operations from Mediator API, web service, and DSP Control clients.

Specifically this topic introduces the sample and provides links to the instructions necessary to download, build, and test the samples.

Topic Map

Requirements 

Download the Sample 

You can install and work with the advanced API samples on any system with ALDSP 3.2 (server 10.1) or ALDSP 3.01 (server 9.2) installed, including the Sample Retail Application provided with ALDSP.

The advanced API samples are available as a ZIP file from:

It is recommended that the ZIP file be extracted into an ALDSP directory such as:

<ALDSP_HOME>/user_projects/workspaces/default/AdvancedAPISamples

Install Workshop 10.2

In order to run the ALDSP Control samples you need to install Workshop 10.2 into the BEA_HOME where your ALDSP server resides.  

You can download WebLogic Workshop 10.2 from:

http://commerce.bea.com/showproduct.jsp?family=WLW&major=10.2&minor=0

Useful References

Introduction

ALDSP enables you to create client projects that invoke data service operations. These client projects can include the following, among others:

  • Java projects that invoke data service functions and procedures using the Data Services Mediator API (also known as the Mediator API)
  • Java-based web service applications using the Mediator API
  • WebLogic Workshop projects (such as portals, business processes, and Web applications) using ALDSP Controls
    See Choosing a Client Programming Model for more information about deciding how to choose a specific client model for accessing ALDSP.

Exploring the Sample Projects

ALDSP includes a set of four sample dataspace projects, based on the Retail Dataspace example provided with ALDSP, that shows how to call ALDSP from client applications using the following:

  • The static and dynamic Java Mediator APIs
  • The static and dynamic Web Service Mediator API
  • A DSP Control using the static and dynamic Mediator APIs

The sample dataspace projects highlight several aspects of the client development process including calling data service operations with different types of arguments and returning different return types.

The sample dataspace projects also demonstrate how to use out-of-band settings (RequestConfig), and show how to perform create, read, update, and delete operations on the data returned.

You can run the Java and Web Service Mediator samples either as standalone applications, or inside web applications. The DSP Control examples, however, must be run inside a container (WebLogic).

Related Topics

Concepts
How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

Understanding the Advanced Static Mediator API Sample

This topic describes how to use the static mediator API to call a data service operation with a complex argument.

You can find the source code for this sample project in the following file:

DSPClientSamplesStatic1/JavaResources/client.java_and_ws.static0/ClientComplexArg.java

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Importing Packages

The first segment of the sample project imports several required packages including the DASResult package which represents the result of invoking an operation on a data service.

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.bea.dsp.das.DASResult;

import weblogic.jndi.Environment;
import java.io.StringWriter;

Note that you could also choose to import the following classes that appear in the generated mediator client JAR file:

import das.ws.retailapplication.customermanagement.ProfileServiceDAS
import das.ejb.retailapplication.customermanagement.ProfileServiceDAS
import retailer.CASE_SERVICE

The ProfileServiceDAS classes (for web services and Java respectively) are the generated DataAccessService classes for the data service. These classes contains type-safe methods that map to the actual data service operations. The CASE_SERVICE class provides the SDO interface for manipulating DataObjects returned from the data service.

Obtaining a Data Access Service Handle

You use a DataAccessService object to call methods (operations) on a data service. For the static mediator API, the DataAccessService (DAS) classes have a factory method named getInstance() which return the handle. The getInstance() method requires two parameters to return the handle:

  • A WebLogic JNDI Context object. The context object allows the Java client to connect to the data service running through a instance of WebLogic server.
  • The name of the dataspace project in which the data service is deployed.
    For more information on the DataAccessService class see:

    For more information on WebLogic JNDI context objects, see Programming WebLogic JNDI:

The ALDSP web service client identifies the DataAccessService class using the URL of the WSDL file. The ALDSP Java client, on the other hand, identifies the DataAccessService class using the dataspace name.
The sample code parses the WSDL URL to determine the dataspace name for the Java client. Note that in a typical application, you would more likely use strings rather than obtaining this information from the WSDL URL.

das.ws.retailapplication.customermanagement.ProfileServiceDAS wsDas = null;
das.ejb.retailapplication.customermanagement.ProfileServiceDAS ejbDas = null;
DASResult<retailer.CASE_SERVICE> dasResult = null;

...

   if(isWebServiceClient()){
      contextCacheKey=locator;
      wsDas=das.ws.retailapplication.customermanagement.ProfileServiceDAS.getInstance(
         new java.util.Hashtable(), contextCacheKey);
   } else {
      splitLocator(locator);
      Context ctx = getInitialContext(uri, username, password);
      ejbDas=das.ejb.retailapplication.customermanagement.ProfileServiceDAS.getInstance(ctx, contextCacheKey);
   }

The sample uses a helper method, getInitialContext(), to get the initial context.

public static InitialContext getInitialContext(String url, String username, String password) throws NamingException {
   Environment env = new Environment();
   env.setProviderUrl(url);
   env.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory");
   env.setSecurityPrincipal(username);
   env.setSecurityCredentials(password);
   return new InitialContext(env.getInitialContext().getEnvironment());
}

Creating the SDO DataFactory

The following code segment shows the use of the HelperContext to create a new DataFactory which you can later use to create new DataObjects.

commonj.sdo.helper.HelperContext hc=com.bea.dsp.das.HelperContextCache.get(contextCacheKey);
commonj.sdo.helper.XMLHelper xh = hc.getXMLHelper();
commonj.sdo.helper.DataFactory factory = hc.getDataFactory();

When using ALDSP 3.0, your clients may need to call the following before making other ALDSP calls:

com.bea.dsp.das.HelperContextCache.setClassLoader(contextCacheKey, Thread.currentThread().getContextClassLoader());

where contextCacheKey is the dataspace name if you are using the Java Mediator API, or the WSDL URL if you are using the Web Service Mediator API.

Retrieving Data from the Service

The generated DataAccessService method getServiceCase(profileService) retrieves the result set from the data service. This method returns all CASE objects corresponding to the specified profile from the data service.

retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class );

   com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
   retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
   profile.setCustomerID("CUSTOMER4");
   profile.setFirstName("dummyFirstName");
   profile.setLastName("dummyLastName");
   profile.setCustomerSince( "2001-01-01");
   profile.setEmailAddress( "dummyEmailAddress");
   profile.setTelephoneNumber("8885551212");

   if(isWebServiceClient()){
      dasResult = wsDas.getServiceCase(profileService);
   } else {
      dasResult = ejbDas.getServiceCase(profileService);
   }

Note that the argument for the setElementName() method must include the namespace URI along with the name of the type of the argument. You can determine the namespace URI by doing the following:

  1. Open RetailDataspace/RetailApplication/CustomerManagement/ProfileService.ds
  2. In the Design View, right-click the getServiceCase function and choose Edit Signature.
  3. Select the PROFILE argument, and click Edit. The Schema file field shows the schema file where the element is defined.
  4. Select and copy the contents of the schema file, choose File > OpenFile, paste the file name into the text box (manually changing the forward slashes to backward slashes), and click Open.
  5. Click Design View for the open schema file.
  6. Locate the PROFILE element and note its type (PROFILE_SERVICE). The namespace URI for the type appears at the top of the Schemas box (urn:retailer).

The method getServiceCase() is mapped directly from the original data service operation of the same name. The operation definition as specified in the data service file appears as follows:

(::pragma  function <f:function kind="navigate" roleName="ServiceCase" visibility="public" xmlns:f="urn:annotations.ld.bea.com"/>::)

declare function tns:getServiceCase($profile as element(ns5:PROFILE)) as element(ns7:CASE)*{
for $b in ns8:getServiceCaseByCustID($profile/ns2:PROFILE/CustomerID)
return $b
};

Obtaining a DataObject from the Result

The return type of the DataAccessService method is a dasResult object, which operates as an iterator. This means that you can use the DASResult.next() method similar to the way you would use the Java method Iterator.next(). The DASResult.next() method returns the next CASE, which is an SDO DataObject. SDO is a Java-based data programming model (API) and architecture for accessing and updating data.

The sample iterates through the dasResult object and outputs the data.

while( dasResult.hasNext()){
   out("DataObject : " + dataObjectToString(xh,(retailer.CASE_SERVICE)dasResult.next()));
}

Disposing the dasResult Object

You must call the DASResult.dispose() method whenever you are finished iterating through a result object. The sample project uses the following code segment to dispose the object:

try {
   if(dasResult!=null) dasResult.dispose();
} catch(Exception e){e.printStackTrace();}

Placing the dispose() call in a try/finally block is a recommended best practice.

ClientComplex.Arg.java Listing

The following lists the code for the ClientComplexArg.java sample project.

ClientComplex.Arg.java Sample Project Code 
package client.java_and_ws.static0;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.bea.dsp.das.DASResult;

import weblogic.jndi.Environment;
import java.io.StringWriter;

public class ClientComplexArg {

   String locator="http://localhost:7001/RetailDataspace/RetailApplication/CustomerManagement/ProfileService.ws?WSDL";
   String dsLocator=null;
   String uri=null;
   String username= "weblogic";
   String password="weblogic";

   java.io.Writer out=new java.io.PrintWriter(System.out);

   String className=this.getClass().getName().substring(this.getClass().getName().lastIndexOf('.')+1);
   String runningIn=this.getClass().getClassLoader().equals(com.bea.dsp.das.DASResult.class.getClassLoader()) ? "standalone" : "webapp";
   String contextCacheKey=null;

   enum ClientType {java, webservice, control};
   ClientType clientType=ClientType.java;
   enum ClassloaderType { noclassloader, currentthread, other};
   ClassloaderType classloaderType=ClassloaderType.noclassloader;

   public ClientComplexArg(){
      this((String)null,(String)null,(String)null, (String)null, null, null);
   }

   public ClientComplexArg(java.io.Writer out){
      this((String)null,(String)null,(String)null, (String)null, out, null);
   }

   public ClientComplexArg(String locator){
      this(locator,(String)null,(String)null, (String)null, null, null);
   }

   public ClientComplexArg(String locator, java.io.Writer out, String classloadertypeStr){
      this(locator,(String)null,(String)null, (String)null, out, classloadertypeStr);
   }

   public ClientComplexArg(String cType, String locator, String username, String password, java.io.Writer out, String classloadertypeStr){
      if(cType != null) this.clientType=ClientType.valueOf(cType);
      if(locator!=null) this.locator=locator;
      if(username!=null) this.username=username;
      if(password!=null)this.password=password;
      if(out!=null) this.out=out;
      if(classloadertypeStr != null) this.classloaderType=ClassloaderType.valueOf(classloadertypeStr);
   }

   public static void main(String[] args) {
      String locator=args.length > 0 ? args[0] : null;
      String uri=args.length > 1 ? args[1] : null;
      String username=args.length > 2 ? args[2] : null;
      String password=args.length > 3 ? args[3] : null;
      String classloadertypeStr=args.length > 4 ? args[4] : null;
      ClientComplexArg c=new ClientComplexArg(locator, uri, username, password, null, classloadertypeStr);
      c.run();
   }

   public void run(){

      if (! locator.startsWith("http://") ){
         out("locator must be http://... (wsdl URL)");
         return;
      }

      das.ws.retailapplication.customermanagement.ProfileServiceDAS wsDas = null;
      das.ejb.retailapplication.customermanagement.ProfileServiceDAS ejbDas = null;
      DASResult<retailer.CASE_SERVICE> dasResult = null;

      try {
         if (isWebServiceClient()){
            contextCacheKey=locator;
            wsDas=das.ws.retailapplication.customermanagement.ProfileServiceDAS.getInstance(new java.util.Hashtable(), contextCacheKey);
         } else {
            splitLocator(locator);
            Context ctx = getInitialContext(uri, username,password);
            ejbDas = das.ejb.retailapplication.customermanagement.ProfileServiceDAS.getInstance(ctx, contextCacheKey);
         }

         commonj.sdo.helper.HelperContext hc=com.bea.dsp.das.HelperContextCache.get(contextCacheKey);
         commonj.sdo.helper.XMLHelper xh = hc.getXMLHelper();
         commonj.sdo.helper.DataFactory factory = hc.getDataFactory();

         retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class );

         com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
         retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
         profile.setCustomerID("CUSTOMER4");
         profile.setFirstName("dummyFirstName");
         profile.setLastName("dummyLastName");
         profile.setCustomerSince( "2001-01-01");
         profile.setEmailAddress( "dummyEmailAddress");
         profile.setTelephoneNumber("8885551212");

         if (isWebServiceClient()){
            dasResult = wsDas.getServiceCase(profileService);
         } else {
            dasResult = ejbDas.getServiceCase(profileService);
         }

         while( dasResult.hasNext()){
            out("DataObject : " + dataObjectToString(xh,(retailer.CASE_SERVICE)dasResult.next()));
         }
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         try {
            if(dasResult!=null) dasResult.dispose();
         } catch(Exception e){e.printStackTrace();}
      }
   }

   public void out(String s){
      try{
         if(out instanceof javax.servlet.jsp.JspWriter)
            s = s.replace("&","&amp;").replace("<", "&lt;").replace(">", "&gt;");
            out.write(className+"/"+runningIn+"/"+clientType+"/"+classloaderType+" "+s+"\n");
            out.flush();
      }catch (Exception e){
         e.printStackTrace();
      }
   }

   public static InitialContext getInitialContext(String url, String username, String password) throws NamingException {
      Environment env = new Environment();
      env.setProviderUrl(url);
      env.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory");
      env.setSecurityPrincipal(username);
      env.setSecurityCredentials(password);
      return new InitialContext(env.getInitialContext().getEnvironment());
   }

   static String dataObjectToString(commonj.sdo.helper.XMLHelper xh, commonj.sdo.DataObject dObj) {
      try {
         com.bea.sdo.PropertyXML element = ((com.bea.sdo.DataObjectXML) dObj).getContainmentPropertyXML();
         String elementName = element.getXMLName();
         String elementURI = element.getXMLNamespaceURI();

         commonj.sdo.helper.XMLDocument xmlDocument = xh.createDocument(dObj, elementURI, elementName);
         StringWriter outputWriter = new StringWriter();
         xh.save(xmlDocument, outputWriter, null);
         return outputWriter.toString();
      } catch (Exception e) {
         e.printStackTrace();
      }
         return null;
   }

   boolean isWebServiceClient(){
      return clientType==ClientType.webservice;
   }

   void splitLocator(String locator) throws Exception {
      uri=null;
      contextCacheKey=null;
      dsLocator=null;
      for(int i=0, j=0, last=0;i<locator.length(); i++) {
         if(locator.charAt(i) == '/') {
            j++;
            if(j==2)
               last=i;
            if(j==3) {
               uri="t3://"+locator.substring(last+1,i);
               last=i;
            }
            if(j==4) {
               contextCacheKey=locator.substring(last+1,i);
               dsLocator="ld:"+locator.substring(i+1).replace(".ws?WSDL", "");
               break;
            }
         }
      }
      if(uri==null || contextCacheKey== null || dsLocator==null)
         throw new Exception("locator not valid : "+locator);
      return;
   }
}

Related Topics

Concepts
How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

How To Set Up the Advanced API Sample Projects

This topic describes how to set up the ALDSP sample projects which illustrate how to call ALDSP data service operations from client applications.

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Installing the ALDSP Retail Dataspace Sample

  1. Launch WorkSpace Studio.
  2. Install the ALDSP Retail Dataspace Sample. The sample creates a dataspace for retail data services that connects to a relational database and web services.
    Depending on whether your are running WebLogic server 10.1 or 9.2 see:

Adding Functions to the Dataspace Project

To add the sample functions to the RetailDataspace project:

  1. Expand the RetailDataspace project in the Project Explorer, and locate the RetailApplication/CustomerManagement/ProfileService.ds data service.

    ProfileService Data Service in the Project Explorer

  2. Double-click the ProfileService.ds data service and click the Source tab.
  3. In the ProfileService.ds data service, add the following functions to the bottom of the Source view:
    declare namespace ord= "ld:Logical/Order/Order";
    
    (::pragma  function <f:function kind="library" visibility="public" isPrimary="false" xmlns:f="urn:annotations.ld.bea.com"/>::)
    declare function tns:getOrderCount($arg as xs:string) as xs:integer {
       count( for $b in ord:getOrderByCustID($arg) return $b)
    };
    
    (::pragma  function <f:function kind="library" visibility="public" isPrimary="false" xmlns:f="urn:annotations.ld.bea.com"/>::)
    declare function tns:getOrderCounts($arg as xs:string) as xs:integer* {
       for $b in ord:getOrderByCustID($arg) return 1
    };
    
    (::pragma  function <f:function kind="library" visibility="public" isPrimary="false" xmlns:f="urn:annotations.ld.bea.com"/>::)
    
    declare function tns:getServiceCases($profiles as element(ns5:PROFILES)) as element(ns7:CASE)* {
       for $profile in $profiles/ns2:PROFILE
       for $b in ns8:getServiceCaseByCustID($profile/CustomerID)
       return $b
    };

    The sample projects call these functions to determine the order count and to retrieve the service cases.

  4. Choose File > Save in the main menu.

Updating the Schema

To update the schema file to support the new functions in the ProfileService.ds data service follow these steps:

  1. Locate the RetailApplication/CustomerManagement/schemas/ProfileService.xsd schema file.

    ProfileService XSD in the Project Explorer

  2. Double-click the ProfileService.xsd schema file and click the Source tab.
  3. In the ProfileService.xsd schema file, add the following lines before </xs:schema> at the bottom of the Source view:
    <xsd:complexType name="PROFILE_SERVICES">
          <xsd:sequence>
             <xsd:element ref="retailerType:PROFILE" minOccurs="0" maxOccurs="unbounded"/>
          </xsd:sequence>
       </xsd:complexType>
    <xsd:element name="PROFILES" type="retailer:PROFILE_SERVICES"/>

    This specifies the PROFILE_SERVICES complex type, which is used by the new functions you added to the ProfileService.ds data service in the previous section.

  4. Choose File > Save in the main menu.
  5. Redeploy the RetailDataspace.

Exporting the Mediator Client JAR Files

Before exporting the Mediator Client JAR files, you need to create a web service map.

To create the web service map:

  1. Right-click the ProfileService.ds data service and choose Create Web Service Map. Click OK to any information dialogs that may appear.

    Creating a Web Service Map

  2. Redeploy the RetailDataspace.

Exporting the Java Mediator Client JAR File 

To export the Java Mediator Client JAR file for the project:

  1. Right-click the RetailDataspace and choose Export.
  2. Expand AquaLogic Data Services Platform, select Mediator Client JAR file, and click Next.

    Selecting Mediator Client JAR File

  3. RetailDataspace should be selected; if not, click the checkbox next to that option.
  4. Choose a convenient destination directory for the RetailDataspace-dsp-client.jar file. Then click Finish. WorkSpace Studio creates the Mediator Client JAR file.

A message indicating that your have successfully exported the mediator JAR file and its location should appear.

Exporting the Java Web Services Mediator Client JAR File 

To export the Java Web Services Mediator Client JAR File:

  1. Right-click the RetailDataspace and choose Export.
  2. Expand AquaLogic Data Services Platform, select Web Services Mediator Client JAR File, and click Next. Notice that the necessary projects and folders are automatically selected.

    Selecting Mediator Client JAR File

  3. Select a destination directory and click Finish. WorkSpace Studio creates the Web Services Mediator Client JAR file.

A message indicating that your have successfully exported the web services mediator JAR file and its location should appear.

Creating the Sample Dataspaces

The sample provides four dataspaces:

  • DSPClientSamplesDynamic1
  • DSPClientSamplesStatic1
  • DSPClientSamplesControlDynamic
  • DSPClientSamplesControlStatic

The dynamic and static client samples illustrate use of the Java and Web Services Mediator APIs. The control dynamic and static samples, illustrate use of ALDSP Control APIs.  

You can create the four sample dataspaces by dowloading and importing the advanced samples ZIP file.

  1. Download the ZIP file from the following location: 
    http://download.oracle.com/docs/cd/E13167_01/aldsp/docs30/code/AdvancedAPISamples.zip
  2. Right-click in the Project Explorer and choose Import.
  3. Expand General, select Existing Projects into Workspace, and click Next.

    Importing Existing Projects into the Workspace

  4. Click Select archive file, click Browse, and open the DspClientSamples_All.zip file.

    Selecting the Sample Dataspace Archive

  5. Click Finish. Studio imports the sample dataspace projects.

Adding the Mediator Client JAR Files

To add your mediator client JAR files to the projects:

  1. In the project explorer copy the mediator client JAR files you generated earlier (RetailDataspace-dsp-client.jar and RetailDataspace-ws-client.jar) to the following folder:
    DSPClientSamplesStatic1/WebContent/WEB-INF/lib
  2. Click Yes To All when prompted to overwrite the existing files.
  3. Right-click the DSPClientSamplesStatic1 dataspace project, and click Refresh.

Setting the Java Build Paths

You need to set the Java build paths to include the specific JAR files required by the projects.

You need to specify the Java build path for all four dataspace projects:

  • DSPClientSamplesStatic1
  • DSPClientSamplesDynamic1
  • DSPClientSamplesControlStatic
  • DSPClientSamplesControlDynamic

To set the Java build path:

  1. In Project Explorer right-click the dataspace project you have selected, then choose:
    Build Path > Configure Build Path

    A dialog appears displaying the properties for the dataspace project.

  2. Click the Libraries tab.
Configuring the Build Path

  1. Click Add External JARs..., then locate and select the indentifed JAR files.
  2. Click Open.
  3. Click OK.

The following table identifies the necessary JAR files and their location for each advanced sample dataspace project. (The ld-client.jar file is needed by all four projects.)

Project, Required JAR Files, and Location 
Dataspace Project JAR File Path
DSPClientSamplesControlDynamic
ld-client.jar
com.bea.core.sdo.1.0.0.0.jar
<ALDSP_HOME>/lib
<BEA_HOME>/modules
DSPClientSamplesControlStatic
ld-client.jar
com.bea.core.sdo.1.0.0.0.jar
<ALDSP_HOME>/lib
<BEA_HOME>/modules
DSPClientSamplesDynamic1
ld-client.jar
weblogic.jar 
<ALDSP_HOME>/lib
<BEA_HOME>/wlserver_10.0/server/lib
DSPClientSamplesStatic1
ld-client.jar 
api.jar
weblogic.jar
<ALDSP_HOME>/lib
<BEA_HOME>/wlserver_10.0/server/lib
<BEA_HOME>/wlserver_10.0/server/lib
When configuring the path for the ALDSP control dataspace projects, you may notice duplicate entries for ld-client.jar and com.bea.sdo.1.0.0.0.jar. If so, retain only the file associated with the location in the above table.

Setting the Run Configurations

You need to create a run configuration for the following projects:

  • DSPClientSamplesDynamic1
  • DSPClientSampleStatic1

Setting the Run Configuration for DSPClientSamplesDynamic1

To set the run configuration for DSPClientSamplesDynamic1:

  1. Right-click DSPClientSamplesDynamic1 in the Project Explorer and choose Run As > Run. The Run dialog appears.
  2. Right-click Java Application, choose New, and type Dynamic as the name of the new run configuration.

    Configuring the Run Configuration Main Class

  3. Enter the following in the Main class field:
    client.java_and_ws.dynamic.RunClients
  4. Click Apply.
  5. Click the Classpath tab. 
Configuring the Run Configuration Classpath

  1. Select Bootstrap Entries > WebLogic System Libraries, and click Remove (if the WebLogic System Libraries entry is present).
  2. Select User Entries
  3. Click Add External JARs
  4. Navigate to:
    <BEA_HOME>/wlserver_10.0/server/lib
  5. select the api.jar file, and click Open.
  6. Click Apply.
  7. Click Close.

Setting the Run Configuration for DSPClientSamplesStatic1

To set the run configuration for DSPClientSamplesStatic1:

  1. Right-click DSPClientSamplesStatic1 in the Project Explorer and choose Run As > Run. The Run dialog appears.
  2. Right-click Java Application, choose New, and type Static as the name of the new run configuration.

    Configuring the Run Configuration Main Class

  3. Enter the following in the Main class field:
    client.java_and_ws.static0.RunClients
  4. Click Apply.
  5. Click Close.

Related Topics

How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

How To Run the Mediator API Sample Projects

This topic describes how to run the Mediator API sample projects.

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Running the Standalone Samples Using the Custom Run Configuration

You can run the following standalone Mediator API sample projects using a custom configuration:

  1. Launch Workspace Studio.
  2. Verify that the server is started and the RetailDataspace sample project is deployed.
    If an unexpected problem is flagged in the Project Explorer, try the Clean project option
    Project > Clean
  3. Make sure the Console window is open:
    Window > Show View > Other > Console
  4. Right-click on DSPClientSamplesStatic1 and choose Run As > Run.
  5. Expand Java Application and select the Static run configuration.
  6. Click Run.

You can run the DSPClientSamplesDynamic1 sample using the steps shown above.

Selecting the Run Configuration

The sample project includes an optional parameter enabling you to choose the following client types:

  • Use java or do not set the parameter to have the sample project use the Mediator API.
  • Use webservice to have the sample project use the Web Service Mediator API.

The parameter can be specified in the Arguments tab as a program argument such as:

webservice
Specifying an Argument

The results appear in the Console Window.

Console After Running Static Mediator Sample with webservice Parameter

Running the Sample Controls Using "Run on Server"

You can run the Mediator API sample controls using the "Run on Server" option.

If you see "Missing Struts Module Configuration" when trying to run the Mediator API sample controls, it is likely because you need to install WebLogic Workshop 10.2 (in addition to what comes with the ALDSP installer).

You can download WebLogic Workshop 10.2 at http://commerce.bea.com/showproduct.jsp?family=WLW&major=10.2&minor=0

To run the sample projects:

  1. Launch Workspace Studio.
  2. Verify that the server is started and the RetailDataspace sample project is deployed.
  3. Right-click the dataspace project and choose Run As > Run on Server.
Selecting the Server

Select the server and click Next.

Adding the Project

Add the required project, and click Finish. You can specify an optional parameter to use the Mediator API or Web Services Mediator API.

Using the Advanced APISample Projects with ALDSP 3.0

The samples are tested with ALDSP 3.2 and 3.01.

If you are using ALDSP 3.0, you need to call the getContextClassLoader() method before accessing the DataAccessService. Specifically, when using the Java or DSP Control Mediator API, call the following method before accessing the DataAccessService:

com.bea.dsp.das.HelperContextCache.setClassLoader("RetailDataspace", Thread.currentThread.getContextClassLoader();

Similarly, when using the Web Services Mediator API, call the following method before accessing the DataAccessService:

com.bea.dsp.das.HelperContextCache.setClassLoader(
   "http://localhost:7001/RetailDataspace/RetailApplication/CustomerManagement/ProfileService.ws?WSDL",
   Thread.currentThread.getContextClassLoader());

Related Topics

How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

Static Mediator API Code Reference

This topic describes the advanced sample project that uses the Static Mediator API to call data service operations from client applications using a variety of argument and return types.

Source:

DSPClientSamplesStatic1/JavaResources/client.java_and_ws.static0

Topic Map

Using a Complex Argument

You can call ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArg.java

Calling an Operation Using a Complex Argument
retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class );

com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getServiceCase(profileService);
} else {
   dasResult = ejbDas.getServiceCase(profileService);
}

Using a Complex Argument List

You can call data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArgList.java

Calling an Operation Using a List of Complex Arguments
retailer.PROFILE_SERVICES profileService =(retailer.PROFILE_SERVICES)factory.create("urn:retailer", "PROFILE_SERVICES");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER6");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getServiceCases(profileService);
} else {
   dasResult = ejbDas.getServiceCases(profileService);
}

Using a Complex Argument with Create-Read-Update-Delete Operations

You can call multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using type-safe setter methods.

The sample then calls the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile.

If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArgs_andCRUD.java

Calling Multiple Operations Using Complex Arguments
com.bea.dsp.sdo.SDOUtil.setElementName(profileService1,	"urn:retailer", "PROFILE");

profileServices[0]=profileService1;

retailertype.PROFILE_TYPE profile1 = profileService1.createPROFILE();
profile1.setCustomerID("CUSTOMER44");
profile1.setFirstName("dummyFirstName");
profile1.setLastName("dummyLastName44");
profile1.setCustomerSince( "2001-01-01");
profile1.setEmailAddress( "dummyEmailAddress");
profile1.setTelephoneNumber("8885551212");

retailer.PROFILE_SERVICE profileService2 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE");

profileServices[1]=profileService2;
retailertype.PROFILE_TYPE profile2 = profileService2.createPROFILE();
profile2.setCustomerID("CUSTOMER55");
profile2.setFirstName("dummyFirstName");
profile2.setLastName("dummyLastName55");
profile2.setCustomerSince( "2001-01-01");
profile2.setEmailAddress( "dummyEmailAddress");
profile2.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getCustomerByCustID("CUSTOMER44");
} else {
   dasResult = ejbDas.getCustomerByCustID("CUSTOMER44");
}

if(!dasResult.hasNext()) {
   out("ADDING: ");

   if(isWebServiceClient()) {
      dasKey = wsDas.createPROFILE(profileServices);
   } else {
      dasKey = ejbDas.createPROFILE(profileServices);
   }

   while( dasKey.hasNext()){
      out("DataObject : " + dataObjectToString(xh, dasKey.next()));
   }

} else {
   retailer.PROFILE_SERVICE dObj= dasResult.next();

   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){
      out("UPDATING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      if(isWebServiceClient()){
         wsDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      } else {
         ejbDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      }
   } else {
      out("DELETING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));

      if(isWebServiceClient()){
         wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      } else {
         ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      }

      if(isWebServiceClient()){
         dasResult = wsDas.getCustomerByCustID("CUSTOMER55");
      } else {
         dasResult = ejbDas.getCustomerByCustID("CUSTOMER55");
      }

      if(dasResult.hasNext()){
         dObj=dasResult.next();
         out("DataObject : " + dataObjectToString(xh,dObj));
         if(isWebServiceClient()){
            wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
         } else {
         ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
         }
      }
   }
}

Returning a Simple Element

You can call ALDSP data service operations that return simple types. The example in this section determines the number of orders by calling the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.

Source:
DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientSimpleReturn.java
Calling an Operation that Returns a Simple Type
java.math.BigInteger count;
if(isWebServiceClient()){
   count = wsDas.getOrderCount("CUSTOMER4");
} else {
   count = ejbDas.getOrderCount("CUSTOMER4");
}

out("DataObject : " + count);

if(isWebServiceClient()){
   dasResult = wsDas.getOrderCounts("CUSTOMER4");
} else {
   dasResult = ejbDas.getOrderCounts("CUSTOMER4");
}

while( dasResult.hasNext()){
   java.math.BigInteger theCount = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + theCount);
}

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when calling methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientWithAudit.java

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

if(isWebServiceClient()){
   dasResult = wsDas.getCustomerByLoginID("Steve", reqConfig);
} else {
   dasResult = ejbDas.getCustomerByLoginID("Steve", reqConfig);
}

com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();
if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         out("Audit Information: " + key + " = " + propMap.get(key));
      }
   }
}

while( dasResult.hasNext()){
   out("DataObject : " + dataObjectToString(xh,(retailer.PROFILE_SERVICE)dasResult.next()));
}

Using Filters

You can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID.

After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when calling the method corresponding to data service operation.

You can find the source code for this sample project in the DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientWithAudit.java file.

Filtering Based on an Identifier
reqConfig = new com.bea.dsp.RequestConfig();
com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery();

filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID");
com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables();
externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5");
filter.setExternalVariables(externalVariables);

/* Alteratively, filter with a hard-coded value */

// filter.addFilter("PROFILE", "PROFILE/PROFILE/CustomerID","=","CUSTOMER5");

reqConfig.setFilter(filter);
try {
   if(isWebServiceClient()){
      dasResult = wsDas.getProfile(reqConfig);
   } else {
      dasResult = ejbDas.getProfile(reqConfig);
   }
}

Related Topics

Concepts
How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

Dynamic Mediator API Code Reference

This topic describes the advanced sample project that uses the Dynamic Mediator API to call ALDSP data service operations from client applications using a variety of argument and return types.

You can find the Java source code for this sample dataspace project in the DSPClientSamplesDynamic1/JavaResources/client.java_and_ws.dynamic folder.

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Using a Complex Argument

You can invoke ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using the set method.

The sample then invokes the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArg.java

Invoking an Operation Using a Complex Argument
commonj.sdo.DataObject profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");

profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCase", new Object[] { profileService });

Using a Complex Argument List

You can invoke ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using the set method.

The sample then invokes the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArgList.java

Invoking an Operation Using a List of Complex Arguments
profileServices = factory.create("urn:retailer", "PROFILE_SERVICES");

com.bea.dsp.sdo.SDOUtil.setElementName(profileServices, "urn:retailer", "PROFILES");
profile = profileServices.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");
profile.set("FirstName", "dummyFirstName4");
profile.set("LastName", "dummyLastName4");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

profile = profileServices.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER6");
profile.set("FirstName", "dummyFirstName6");
profile.set("LastName", "dummyLastName6");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCases", new Object[] { profileServices });

Using a Complex Argument with Create-Read-Update-Delete Operations

You can invoke multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using the setElementName method.

The sample then invokes the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile.

If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientComplexArgs_andCRUD.java

Invoking Multiple Operations Using Complex Arguments
profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
profileServices.add(profileService);
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
profile1 = profileService.createDataObject("PROFILE");
profile1.set("CustomerID", "CUSTOMER44");
profile1.set("FirstName", "dummyFirstName44");
profile1.set("LastName", "dummyLastName44");
profile1.set("CustomerSince", "2001-01-01");
profile1.set("EmailAddress", "dummyEmailAddress");
profile1.set("TelephoneNumber", "8885551212");

profileService = factory.create("urn:retailer", "PROFILE_SERVICE");
profileServices.add(profileService);
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
profile2 = profileService.createDataObject("PROFILE");
profile2.set("CustomerID", "CUSTOMER55");
profile2.set("FirstName", "dummyFirstName55");
profile2.set("LastName", "dummyLastName55");
profile2.set("CustomerSince", "2001-01-01");
profile2.set("EmailAddress", "dummyEmailAddress");
profile2.set("TelephoneNumber", "8885551212");

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER44" });

if(!dasResult.hasNext()) {
   out("ADDING: ");

   dasResult = (com.bea.dsp.das.DASResult) das.invoke("createPROFILE", new Object[] { profileServices.toArray() });

   while( dasResult.hasNext()) {
      out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next()));
   }

} else {
   commonj.sdo.DataObject dObj=(commonj.sdo.DataObject)dasResult.next();
   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))) {
      out("UPDATING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("updatePROFILE", new Object[] { dObj });
   } else {
      out("DELETING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj });
      dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER55" });

      if(dasResult.hasNext()) {
         dObj=(commonj.sdo.DataObject)dasResult.next();
         out("DataObject : " + dataObjectToString(xh,dObj));
         dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj });
      }
   }
}

Returning a Simple Element

You can invoke ALDSP data service operations that return simple types. The example in this section determines the number of orders by invoking the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientSimpleReturn.java

Invoking an Operation that Returns a Simple Type
dasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCount", new Object[] {"CUSTOMER4"});

while( dasResult.hasNext()) {
   java.math.BigInteger count = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + count);
}

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCounts", new Object[] {"CUSTOMER4"});

while( dasResult.hasNext()) {
   java.math.BigInteger count = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + count);
}

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when invoking methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientWithAudit.java

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByLoginID", new Object[] { "Steve" }, reqConfig);

com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();
if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         out("Audit Information: " + key + " = " + propMap.get(key));
      }
   }
}

while( dasResult.hasNext()) {
   out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next()));
}

Using Filters

You can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID.

After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when invoking the method corresponding to data service operation.

Source:

DSPClientSamplesDynamic1/Java Resources/src/client.java_and_ws.dynamic/ClientWithAudit.java

Filtering Based on an Identifier
reqConfig = new com.bea.dsp.RequestConfig();
com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery() ;

filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID");
com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables();
externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5");
filter.setExternalVariables(externalVariables);

/* Or filter with hard-coded value */

// filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","CUSTOMER5");

reqConfig.setFilter(filter);
try {
   dasResult = das.invoke("getProfile", new Object[] {}, reqConfig);
}

Related Topics

Concepts
How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

ALDSP Control Static Mediator API Code Reference

This topic describes the advanced sample project that uses the Static Mediator API to call data service operations from ALDSP Controls using a variety of argument and return types.

Source:

DSPClientSamplesControlStatic/Java Resources/src/dspControl/DspControlController.java

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Using a Complex Argument

You can call ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.

Calling an Operation Using a Complex Argument
retailer.PROFILE_SERVICE profileService = (retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class );

com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

retailer.CASE_SERVICE[] cases=DSPControlFile.getServiceCase(profileService);

Using a Complex Argument List

You can call ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.

Calling an Operation Using a List of Complex Arguments
retailer.PROFILE_SERVICES profileService =(retailer.PROFILE_SERVICES)factory.create("urn:retailer", "PROFILE_SERVICES");

com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER6");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

retailer.CASE_SERVICE[] cases = DSPControlFile.getServiceCases(profileService);

Using a Complex Argument with Create-Read-Update-Delete Operations

You can call multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including calling create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using type-safe setter methods.

The sample then calls the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile.

If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.

Calling Multiple Operations Using Complex Argument
retailer.PROFILE_SERVICE[] profileServices = new retailer.PROFILE_SERVICE[2];

retailer.PROFILE_SERVICE profileService1 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE");

com.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE");

profileServices[0]=profileService1;

retailertype.PROFILE_TYPE profile1 = profileService1.createPROFILE();
profile1.setCustomerID("CUSTOMER44");
profile1.setFirstName("dummyFirstName");
profile1.setLastName("dummyLastName44");
profile1.setCustomerSince( "2001-01-01");
profile1.setEmailAddress( "dummyEmailAddress");
profile1.setTelephoneNumber("8885551212");

retailer.PROFILE_SERVICE profileService2 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE");

profileServices[1]=profileService2;
retailertype.PROFILE_TYPE profile2 = profileService2.createPROFILE();
profile2.setCustomerID("CUSTOMER55");
profile2.setFirstName("dummyFirstName");
profile2.setLastName("dummyLastName55");
profile2.setCustomerSince( "2001-01-01");
profile2.setEmailAddress( "dummyEmailAddress");
profile2.setTelephoneNumber("8885551212");

retailer.PROFILE_SERVICE[] returnedProfileServices=DSPControlFile.getCustomerByCustID("CUSTOMER44");

outputString="";
if(returnedProfileServices.length==0) {
   outputString=outputString +"ADDING: \n";
   DSPControlFile.createPROFILE(profileServices);
   outputString=outputString + dataObjectsToString(profileServices);
} else {
   retailer.PROFILE_SERVICE dObj= returnedProfileServices[0];
   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))) {
      outputString=outputString +"UPDATING: \n";
      outputString=outputString + dataObjectsToString(profileServices);
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      DSPControlFile.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
   } else {
      outputString=outputString +"DELETING: \n";
      outputString=outputString + dataObjectsToString(returnedProfileServices);

      DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      returnedProfileServices=DSPControlFile.getCustomerByCustID("CUSTOMER55");

      if(returnedProfileServices.length>0) {
         dObj = returnedProfileServices[0];
         outputString=outputString + dataObjectsToString(returnedProfileServices);
         DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      }
   }
}

Returning a Simple Element

You can call ALDSP data service operations that return simple types. The example in this section determines the number of orders by calling the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.

Calling an Operation that Returns a Simple Type
java.math.BigInteger count = DSPControlFile.getOrderCount("CUSTOMER4");
outputString=outputString + dataObjectsToString(new Object[]{count});
java.math.BigInteger[] counts = DSPControlFile.getOrderCounts("CUSTOMER4");
outputString=outputString + dataObjectsToString(counts);

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when calling methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

retailer.PROFILE_SERVICE profileService[] = DSPControlFile.getCustomerByLoginID("Steve", reqConfig);
outputString=dataObjectsToString(profileService);

com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();
if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         outputString=outputString + "Audit Information: " + key + " = " + propMap.get(key)+"\n";
      }
   }
}

Related Topics

Concepts
How Tos
Reference

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

ALDSP Control Dynamic Mediator API Code Reference

This topic the advanced sample project that uses the Dynamic Mediator API to invoke data service operations from ALDSP Controls using a variety of argument and return types.

Source:

DSPClientSamplesControlDynamic/Java Resources/src/dspControl/DspControlController.java

Topic Map


Advanced API Samples - Mediator, Web Services, and DSP Controls

Using a Complex Argument

You can invoke ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using the set method.

The sample then creates a query to call the getServiceCase operation, using the complex argument, to retrieve the CASE information.

Calling an Operation Using a Complex Argument
commonj.sdo.DataObject profileService =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");
profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileService), true);
StringBuffer query=new StringBuffer();
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("declare namespace retailer='urn:retailer';\n");
query.append("declare variable $profile as element(retailer:PROFILE) external;\n");
query.append("tns:getServiceCase($profile)");
Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables);

Using a Complex Argument List

You can invoke ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using the set method.

The sample then creates a query to call the getServiceCase operation, using the argument consisting of the list of complex objects, to retrieve the CASE information.

Invoking an Operation Using a List of Complex Arguments
commonj.sdo.DataObject profileService =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICES");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES");
commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER4");
profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

profile = profileService.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER6");
profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("profiles"), dataObject2String(xh,profileService), true);
StringBuffer query=new StringBuffer();
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("declare namespace retailer='urn:retailer';\n");
query.append("declare variable $profiles as element(retailer:PROFILES) external;\n");
query.append("tns:getServiceCases($profiles)");
Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables);

Using a Complex Argument with Create-Read-Update-Delete Operations

You can invoke multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using the set method.

The sample then creates a query to call the getCustomerByCustID operation using a complex argument and checks whether the customer information is already stored. If not, the sample creates a query to call the createPROFILE operation to create the customer profile.

If a record already exists for the customer, the sample creates a query to call the updatePROFILE operation to store the new information in the profileService object. If an existing record does not match, the sample creates a query to call the deletePROFILE operation to remove the customer profile.

Invoking Multiple Operations Using Complex Arguments
retailer.PROFILE_SERVICE[] profileServices = new retailer.PROFILE_SERVICE[2];
commonj.sdo.DataObject profileService1 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE");
profileServices[0]=(retailer.PROFILE_SERVICE)profileService1;

commonj.sdo.DataObject profile = profileService1.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER44");
profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName44");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

commonj.sdo.DataObject profileService2 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE");

profileServices[1]=(retailer.PROFILE_SERVICE)profileService2;

profile = profileService2.createDataObject("PROFILE");
profile.set("CustomerID", "CUSTOMER55");
profile.set("FirstName", "dummyFirstName");
profile.set("LastName", "dummyLastName55");
profile.set("CustomerSince", "2001-01-01");
profile.set("EmailAddress", "dummyEmailAddress");
profile.set("TelephoneNumber", "8885551212");

StringBuffer query=new StringBuffer();
query.append("declare variable $customerId as xs:string external;\n");
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("tns:getCustomerByCustID($customerId)");
com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER44", true);
Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );

outputString="";
if(returnedProfileServices.length==0) {
   outputString=outputString +"ADDING: \n";

   /*
   extVariables=new com.bea.ld.ExternalVariables();
   extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileServices), true);
   query=new StringBuffer();
   query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
   query.append("declare namespace retailer='urn:retailer';\n");
   query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
   query.append("tns:createPROFILE($profile)");
   returnedProfileServices=DSPControlFile.executeProcedure(query.toString(), extVariables);
   */

   returnedProfileServices=DSPControlFile.createPROFILE(profileServices);
   outputString=outputString + dataObjectsToString(returnedProfileServices);
} else {
   commonj.sdo.DataObject dObj= (commonj.sdo.DataObject)returnedProfileServices[0];
   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){
      outputString=outputString +"UPDATING: \n";
      outputString=outputString + dataObjectsToString(profileServices);
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      DSPControlFile.updatePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

      /*
      extVariables=new com.bea.ld.ExternalVariables();
      extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,dObj), true);
      query=new StringBuffer();
      query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
      query.append("declare namespace retailer='urn:retailer';\n");
      query.append("declare variable $profile as changed-element(retailer:PROFILE)* external;\n");
      query.append("tns:updatePROFILE($profile)");
      DSPControlFile.executeProcedure(query.toString(), extVariables);
      */

   } else {
      outputString=outputString +"DELETING: \n";
      outputString=outputString + dataObjectsToString(returnedProfileServices);
      DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

      /*
      extVariables=new com.bea.ld.ExternalVariables();
      extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true);
      query=new StringBuffer();
      query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
      query.append("declare namespace retailer='urn:retailer';\n");
      query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
      query.append("tns:deletePROFILE($profile)");
      DSPControlFile.executeProcedure(query.toString(), extVariables);
      */

      query=new StringBuffer();
      query.append("declare variable $customerId as xs:string external;\n");
      query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
      query.append("tns:getCustomerByCustID($customerId)");
      extVariables=new com.bea.ld.ExternalVariables();
      extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER55", true);
      returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );

      if(returnedProfileServices.length>0) {
         dObj= (commonj.sdo.DataObject)returnedProfileServices[0];
         outputString=outputString + dataObjectsToString(returnedProfileServices);
         DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj});

         /*
         extVariables=new com.bea.ld.ExternalVariables();
         extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true);
         query=new StringBuffer();
         query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
         query.append("declare namespace retailer='urn:retailer';\n");
         query.append("declare variable $profile as element(retailer:PROFILE)* external;\n");
         query.append("tns:deletePROFILE($profile)");
         DSPControlFile.executeProcedure(query.toString(), extVariables);
         */
      }
   }
}

Returning a Simple Element

You can invoke ALDSP data service operations that return simple types. The example in this section determines the number of orders by creating a query to call the getOrderCount and getOrderCounts operations and assigning the results to variables of type java.math.BigInteger.

Invoking an Operation that Returns a Simple Type
outputString="";
StringBuffer query=new StringBuffer();
query.append("declare variable $customerId as xs:string external;\n");
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("tns:getOrderCount($customerId)");
com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables);
outputString=outputString + dataObjectsToString(new Object[]{returnedProfileServices});

query=new StringBuffer();
query.append("declare variable $customerId as xs:string external;\n");
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("tns:getOrderCounts($customerId)");
extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables );
outputString=outputString + dataObjectsToString(returnedProfileServices);

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when invoking operations. The example then retrieves the audit records and iterates through the results to output for display.

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

StringBuffer query=new StringBuffer();
query.append("declare variable $customerId as xs:string external;\n");
query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n");
query.append("tns:getCustomerByCustID($customerId)");
com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables();
extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true);
Object[] o=DSPControlFile.executeQuery(query.toString(), extVariables, reqConfig );
outputString=dataObjectsToString(o);
/** Dump out the audit information **/
com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();

if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         outputString=outputString + "Audit Information: " + key + " = " + propMap.get(key)+"\n";
      }
   }
}

Related Topics

Concepts
How Tos
Reference
Document generated by Confluence on Jul 03, 2008 12:11